<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.naming.*"%>
<%!
void listContextObjects(PrintWriter pw, Context ctx, int level) throws Exception {
	if (level > 5) return;
	NamingEnumeration ne = ctx.list("");
	while (ne.hasMore()) {
    	Object o = ne.next();
    	for (int i = 0; i < level; i++)
        	pw.print("    ");
    	pw.println("obj: " + o);
    	if (o instanceof javax.naming.NameClassPair) {
    		NameClassPair pair = (NameClassPair) o;
        	Object oo = ctx.lookup(pair.getName());
			if (oo instanceof javax.naming.Context) {
                listContextObjects(pw, (Context) oo, level+1);
			}
    	}
	}
}

class task extends Thread {

    PrintWriter pw;
    Context ctx;
    int level;

	public task(PrintWriter pw) {
        this.pw = pw;
	}

//	public task(PrintWriter pw, Context ctx, int level) {
//        this.pw = pw;
//        this.ctx = ctx;
//        this.level = level;
//	}

    public void run() {
        try {
        javax.naming.InitialContext ctx = new javax.naming.InitialContext();
        Object obj = ctx.lookup("java:comp/UserTransaction");
        Object ut = ctx.lookup("jta/usertransaction");
        pw.println("find object: " + ut + " hashCode: " + obj.hashCode());
        pw.println("find object: " + obj + " hashCode: " + obj.hashCode());
        pw.println("find object: " + ((Context) obj).lookup("UserTransaction") + " hashCode: " + ((Context) obj).lookup("java:comp/UserTransaction").hashCode());
//        listContextObjects(pw, ctx, level);
        }
        catch (Exception e) {
         	e.printStackTrace(pw);
        }
    }
}


%>

<PRE>

<%

net.sf.hibernate.Session hs = null;
try {
//	net.sf.hibernate.SessionFactory hsf =
//    (net.sf.hibernate.SessionFactory)
//    com.hollycrm.springframework.factory.DefaultBeanFactory.getBean("sessionFactory");
//    hs = hsf.openSession();
//
//    out.println(hs.find("from SheetCategory"));
//
//    org.springframework.orm.hibernate.HibernateTemplate ht =
//    (org.springframework.orm.hibernate.HibernateTemplate)
//    com.hollycrm.springframework.factory.DefaultBeanFactory.getBean("hibernateTemplate");
//
//	out.println(com.hollycrm.unicom.usersupport.hibernate.OracleHibernateUserSupportHelper.getDepartmentTreeList(hs, ht));


		javax.naming.InitialContext ctx = new javax.naming.InitialContext();
        out.println("Context: " + ctx + " Env: " + ctx.getEnvironment());
        Object obj = ctx.lookup("");
        out.println("find object: " + obj + " hashCode: " + obj.hashCode());
        out.println("find object: " + ((Context) obj).lookup("java:comp/UserTransaction") + " hashCode: " + ((Context) obj).lookup("java:comp/UserTransaction").hashCode());
//        out.println("find object: " + ((Context) obj).lookup("jta/usertransaction") + " hashCode: " + ((Context) obj).lookup("jta/usertransaction").hashCode());

		Thread thread = new task(new PrintWriter(out));
		thread.start();

        Thread.currentThread().sleep(1000L);

//        try {
//        	thread.interrupt();
//        }
//        catch (Exception e) {
//            e.printStackTrace(new PrintWriter(out));
//        }

//        listContextObjects(new PrintWriter(out), (Context)obj, 1);
}
catch (Exception e) {
	e.printStackTrace(response.getWriter());
}
finally {
//    hs.close();
}


%>
</pre>
